home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / hplip / ui4 / plugindialog.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  9.0 KB  |  229 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from base.g import *
  5. from base import device, utils
  6. from prnt import cups
  7. from base.codes import *
  8. from ui_utils import *
  9. from installer.core_install import CoreInstall
  10. from PyQt4.QtCore import *
  11. from PyQt4.QtGui import *
  12. from plugindialog_base import Ui_Dialog
  13. PAGE_SOURCE = 0
  14. PAGE_MAX = 1
  15.  
  16. class PluginDialog(QDialog, Ui_Dialog):
  17.     
  18.     def __init__(self, parent, install_mode = PLUGIN_NONE):
  19.         QDialog.__init__(self, parent)
  20.         self.install_mode = install_mode
  21.         self.plugin_path = None
  22.         self.result = False
  23.         self.core = CoreInstall()
  24.         self.core.set_plugin_version()
  25.         self.setupUi(self)
  26.         self.initUi()
  27.         QTimer.singleShot(0, self.showSourcePage)
  28.  
  29.     
  30.     def isPluginInstalled(self):
  31.         return self.core.check_for_plugin()
  32.  
  33.     
  34.     def initUi(self):
  35.         self.connect(self.CancelButton, SIGNAL('clicked()'), self.CancelButton_clicked)
  36.         self.connect(self.NextButton, SIGNAL('clicked()'), self.NextButton_clicked)
  37.         self.setWindowIcon(QIcon(load_pixmap('prog', '48x48')))
  38.  
  39.     
  40.     def showSourcePage(self):
  41.         if self.install_mode == PLUGIN_REQUIRED:
  42.             self.TitleLabel.setText(self._PluginDialog__tr('An additional driver plug-in is required to operate this printer. You may download the plug-in directly from an HP authorized server (recommended), or, if you already have a copy of the file, you can specify a path to the file (advanced).'))
  43.             self.SkipRadioButton.setEnabled(False)
  44.         elif self.install_mode == PLUGIN_OPTIONAL:
  45.             self.TitleLabel.setText(self._PluginDialog__tr('An optional driver plug-in is available to enhance the operation of this printer. You may download the plug-in directly from an HP authorized server (recommended), skip this installation (not recommended), or, if you already have a copy of the file, you can specify a path to the file (advanced).'))
  46.         
  47.         self.connect(self.DownloadRadioButton, SIGNAL('toggled(bool)'), self.DownloadRadioButton_toggled)
  48.         self.connect(self.CopyRadioButton, SIGNAL('toggled(bool)'), self.CopyRadioButton_toggled)
  49.         self.connect(self.SkipRadioButton, SIGNAL('toggled(bool)'), self.SkipRadioButton_toggled)
  50.         self.connect(self.PathLineEdit, SIGNAL('textChanged(const QString &)'), self.PathLineEdit_textChanged)
  51.         self.connect(self.BrowseToolButton, SIGNAL('clicked()'), self.BrowseToolButton_clicked)
  52.         self.BrowseToolButton.setIcon(QIcon(load_pixmap('folder_open', '16x16')))
  53.         self.displayPage(PAGE_SOURCE)
  54.  
  55.     
  56.     def DownloadRadioButton_toggled(self, b):
  57.         if b:
  58.             self.PathLineEdit.setEnabled(False)
  59.             self.BrowseToolButton.setEnabled(False)
  60.             self.NextButton.setEnabled(True)
  61.             
  62.             try:
  63.                 self.PathLineEdit.setStyleSheet('')
  64.             except AttributeError:
  65.                 pass
  66.  
  67.             self.plugin_path = None
  68.         
  69.  
  70.     
  71.     def CopyRadioButton_toggled(self, b):
  72.         if b:
  73.             self.PathLineEdit.setEnabled(True)
  74.             self.BrowseToolButton.setEnabled(True)
  75.             self.plugin_path = unicode(self.PathLineEdit.text())
  76.             self.setPathIndicators()
  77.         
  78.  
  79.     
  80.     def SkipRadioButton_toggled(self, b):
  81.         if b:
  82.             self.PathLineEdit.setEnabled(False)
  83.             self.BrowseToolButton.setEnabled(False)
  84.             self.NextButton.setEnabled(True)
  85.             
  86.             try:
  87.                 self.PathLineEdit.setStyleSheet('')
  88.             except AttributeError:
  89.                 pass
  90.  
  91.             self.plugin_path = None
  92.         
  93.  
  94.     
  95.     def PathLineEdit_textChanged(self, t):
  96.         self.plugin_path = unicode(t)
  97.         self.setPathIndicators()
  98.  
  99.     
  100.     def setPathIndicators(self):
  101.         ok = True
  102.         if (not (self.plugin_path) or self.plugin_path) and os.path.isdir(self.plugin_path):
  103.             self.PathLineEdit.setToolTip(self._PluginDialog__tr("You must specify a path to the '%1' file.").arg(self.core.plugin_name))
  104.             ok = False
  105.         elif os.path.basename(self.plugin_path) != self.core.plugin_name:
  106.             self.PathLineEdit.setToolTip(self._PluginDialog__tr("The plugin filename must be '%1'.").arg(self.core.plugin_name))
  107.             ok = False
  108.         
  109.         if not ok:
  110.             
  111.             try:
  112.                 self.PathLineEdit.setStyleSheet('background-color: yellow; ')
  113.             except AttributeError:
  114.                 pass
  115.  
  116.             self.NextButton.setEnabled(False)
  117.         else:
  118.             
  119.             try:
  120.                 self.PathLineEdit.setStyleSheet('')
  121.             except AttributeError:
  122.                 pass
  123.  
  124.             self.NextButton.setEnabled(True)
  125.             self.PathLineEdit.setToolTip(QString(''))
  126.  
  127.     
  128.     def BrowseToolButton_clicked(self):
  129.         t = unicode(self.PathLineEdit.text())
  130.         if not os.path.exists(t):
  131.             path = unicode(QFileDialog.getOpenFileName(self, self._PluginDialog__tr('Select Plug-in File'), user_conf.workingDirectory(), self._PluginDialog__tr('Plugin Files (*.run)')))
  132.         
  133.         if path:
  134.             self.plugin_path = path
  135.             self.PathLineEdit.setText(self.plugin_path)
  136.             user_conf.setWorkingDirectory(self.plugin_path)
  137.         
  138.         self.setPathIndicators()
  139.  
  140.     
  141.     def displayPage(self, page):
  142.         self.updateStepText(page)
  143.         self.StackedWidget.setCurrentIndex(page)
  144.  
  145.     
  146.     def CancelButton_clicked(self):
  147.         self.close()
  148.  
  149.     
  150.     def NextButton_clicked(self):
  151.         if self.SkipRadioButton.isChecked():
  152.             log.debug('Skipping plug-in installation.')
  153.             self.close()
  154.             return None
  155.         if self.plugin_path is None:
  156.             plugin_conf_url = self.core.get_plugin_conf_url()
  157.             log.info('Downloading configuration file from: %s' % plugin_conf_url)
  158.             (self.plugin_path, size, checksum, timestamp, ok) = self.core.get_plugin_info(plugin_conf_url, self.plugin_download_callback)
  159.             print self.plugin_path, size, checksum, timestamp, ok
  160.             log.debug('path=%s, size=%d, checksum=%s, timestamp=%f, ok=%s' % (self.plugin_path, size, checksum, timestamp, ok))
  161.             if not self.plugin_path.startswith('http://') and not self.plugin_path.startswith('file://'):
  162.                 self.plugin_path = 'file://' + self.plugin_path
  163.             
  164.         elif not self.plugin_path.startswith('http://'):
  165.             self.plugin_path = 'file://' + self.plugin_path
  166.         
  167.         (size, checksum, timestamp) = (0, '', 0)
  168.         log.info('Downloading plug-in from: %s' % self.plugin_path)
  169.         (ok, local_plugin) = self.core.download_plugin(self.plugin_path, size, checksum, timestamp, self.plugin_download_callback)
  170.         if not ok:
  171.             log.error('Plug-in download failed: %s' % local_plugin)
  172.             FailureUI(self, self._PluginDialog__tr('Plug-in download failed.'))
  173.             self.close()
  174.             return None
  175.         if not self.core.run_plugin(GUI_MODE, self.plugin_install_callback):
  176.             FailureUI(self, self._PluginDialog__tr('Plug-in install failed.'))
  177.             self.close()
  178.             return None
  179.         cups_devices = device.getSupportedCUPSDevices([
  180.             'hp'])
  181.         for dev in cups_devices:
  182.             mq = device.queryModelByURI(dev)
  183.             if mq.get('fw-download', False):
  184.                 log.info(log.bold('\nDownloading firmware to device %s...' % dev))
  185.                 
  186.                 try:
  187.                     d = None
  188.                     
  189.                     try:
  190.                         d = device.Device(dev)
  191.                     except Error:
  192.                         self.core.run_plugin(GUI_MODE, self.plugin_install_callback)
  193.                         self.core.run_plugin(GUI_MODE, self.plugin_install_callback)
  194.                         ok
  195.                         log.error('Error opening device.')
  196.                         continue
  197.                     except:
  198.                         None if self.plugin_path.startswith('file://') else ok
  199.  
  200.                     if d.downloadFirmware():
  201.                         log.info('Firmware download successful.\n')
  202.                 finally:
  203.                     pass
  204.  
  205.                 continue
  206.             self.core.run_plugin(GUI_MODE, self.plugin_install_callback)
  207.         
  208.         SuccessUI(self, self._PluginDialog__tr('Plug-in install successful.'))
  209.         self.result = True
  210.         self.close()
  211.  
  212.     
  213.     def plugin_download_callback(self, c, s, t):
  214.         pass
  215.  
  216.     
  217.     def plugin_install_callback(self, s):
  218.         print s
  219.  
  220.     
  221.     def updateStepText(self, p):
  222.         self.StepText.setText(self._PluginDialog__tr('Step %1 of %2').arg(p + 1).arg(PAGE_MAX + 1))
  223.  
  224.     
  225.     def __tr(self, s, c = None):
  226.         return qApp.translate('PluginDialog', s, c)
  227.  
  228.  
  229.